package com.hopu.oa.dao.process;

import com.hopu.oa.entity.management.AoaStatusList;
import com.hopu.oa.entity.process.*;
import com.hopu.oa.entity.user.AoaUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 流程审核
 */
@Repository
@Mapper
public interface auditDao {

    List<ProcessAll> findAll(@Param("userId") Integer userId, @Param("find") String find, @Param("index") Integer index, @Param("size") Integer size);

    //通过statusId查询状态名称
    @Select("select * from aoa_status_list where status_id = #{statusId}")
    AoaStatusList selectStatusById(@Param("statusId") Integer statusId);

    @Select("select * from aoa_process_list where process_id = #{proId}")
    AoaProcessList selectProcess(@Param("proId") Integer proId);
//    List<AoaProcessList> selectProcessStatus(@Param("userId")Integer userId, @Param("find") String find, @Param("index")Integer index, @Param("size")Integer size);

    @Delete("delete from aoa_process_list where process_id = #{processId}")
    int deleteProcess(@Param("processId") Integer processId);

    //审核/////////////////////////////////////////////////////////////
    List<AoaUser> findUserInfoByName(Integer userId, String userName, @Param("index") int index, @Param("size") int size, int roleId);

    List<AoaUser> MailFindUserInfoByName(Integer userId, String userName, @Param("index") int index, @Param("size") int size, int roleId);

    AoaProcessList selectOneById(int id);

    List<AoaReviewed> selectReviewedByid(int pid);

    @Select("select * from aoa_bursement where pro_id=#{pid}")
    AoaBursement selectBursementById(int pid);

    @Select("select * from aoa_evectionMoney where pro_id=#{pid}")
    AoaEvectionmoney selectEvectionMoneyById(int pid);

    @Update("update aoa_reviewed set advice=#{advice},reviewed_time=#{reviewedTime},status_id=#{statusId} where pro_id=#{proId} and user_id=#{uid}")
    int updateReviewed(String advice, String reviewedTime, int statusId, int proId, int uid);

    @Update("update aoa_reviewed set status_id=#{statusId} where pro_id=#{proId}")
    int updateReviewedAllUser(int statusId, int proId);


    @Insert("insert into aoa_reviewed (status_id,pro_id,user_id,del) VALUES(23,#{proId},#{uid},0)")
    int insertIntoReviewed(int proId, int uid);

    @Update("update aoa_process_list set status_id=#{statusId} where process_id=#{proid}")
    int updateProcessByid(int statusId, int proid);

    @Select("select user_id from aoa_user where user_name=#{username}")
    int selectIDByName(String name);

    @Select("select * from aoa_reviewed  where pro_id=#{proId} and user_id=#{uid}")
    AoaReviewed selectByid(int proId, int uid);

//////////////////////////////////////////////////////////////////

    //判断是否已流转过
    @Select("select * from aoa_reviewed where pro_id =#{proId} and user_id = #{userId} ")
    AoaReviewed selectReviewedYN(@Param("proId") Integer proId, @Param("userId") Integer userId);

    //判断对应的申请审核是否还有未处理
    @Select("select * from aoa_reviewed where pro_id =#{proId}")
    List<AoaReviewed> selectReviewedStatusId(@Param("proId") Integer proId);

    //若其他审批人已流转，则删除未处理的
    @Delete("delete from  aoa_reviewed where pro_id =#{proId} and status_id = 23")
    int deleteReviewedByNoDeal(@Param("proId") Integer proId);
}
